module ICarry {

    export class IntroViewModel implements PrismBreak.PbViewModel {

        private _app: ICarryApplication;
        private _view: PrismBreak.View;

        private nextToken: string;

        constructor(app: PrismBreak.PbApp) {
            this._app = <ICarryApplication>app;

            this._app.EventManager.Subscribe(PrismBreak.EventType[PrismBreak.EventType.FrameworkInitialized], () => {
                this._app.ViewManager.ActivateView(this._view);
            });



        }

        public Initialize(view: PrismBreak.View) {
            ko.applyBindings(this, view.Node);

            this._view = <PrismBreak.View> view;
        }

        public Activated() {
            //Start listening to next event
            this.nextToken = this._app.EventManager.Subscribe(PrismBreak.EventType[PrismBreak.EventType.RequestNextStep], () => {
                this.GoToNextStep();
            });
        }

        private GoToNextStep(): void {

            if (this.CanGoNext) {
                //Stop listening to next event
                this._app.EventManager.Unsubscribe(PrismBreak.EventType[PrismBreak.EventType.RequestNextStep], this.nextToken);

                //activate next view
                this._app.ViewManager.ActivateViewById("RequestOfferView");
            }
        }

        private CanGoNext(): boolean {
            //TODO: do some validation
            return true;
        }

    }

}  